﻿<?php

class Zend_View_Helper_ConvertDate extends Zend_View_Helper_Abstract
{
   /**
     * Convert date
     *
     * Converts yyyy-mm-dd to dd-mm-yyyy resp. dd-mm-yyyy to yyyy-mm-dd
     *
     * @param string $date
     */
    public function convertDate($date)
    {
        if (preg_match('/^(\d){4}(-)(\d){2}(-)(\d){2}$/', $date)) {
            return substr($date, 8, 2) . '-' . substr($date, 5, 2) . '-' . substr($date, 0, 4);
        } elseif (preg_match('/^(\d){2}(-)(\d){2}(-)(\d){4}$/', $date)) {
            return substr($date, 6, 4) . '-' . substr($date, 3, 2) . '-' . substr($date, 0, 2);
        } else {
            return null;
        }
    }
}